
// FillDiskPublicDlg.h : header file
//

/*
*****************************************************************************
*                                                                           *
*   Program functions:                                                      *
*                                                                           *
*   Fill hard disk(s) by dummy files                                        *
*                                                                           *
*   Author: Allan Qiu                                                       *
*                                                                           *
*   Version: 1.1.0.1                                                        *
*                                                                           *
*   Latest update: 2012-06-17 by Allan Qiu                                  *
*                                                                           *
*****************************************************************************
*/

#pragma once

// Hard Driver letter: A - Z, total 26
#define INT_DISKCOUNT			26

// The function works on background thread for FAT32/FAT16 disks.
UINT FillDiskFAT32Thread(LPVOID pParam);

// CFillDiskPublicDlg dialog
class CFillDiskPublicDlg : public CDialogEx
{
// Construction
public:
	CFillDiskPublicDlg(CWnd* pParent = NULL);	// standard constructor
	virtual ~CFillDiskPublicDlg();

// Dialog Data
	enum { IDD = IDD_FILLDISKPUBLIC_DIALOG };

	protected:
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV support


// Implementation
protected:
	HICON m_hIcon;

	// Generated message map functions
	virtual BOOL OnInitDialog();
	afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();
	DECLARE_MESSAGE_MAP()

private:
	// The command line args is (or not) correct?
	bool m_bStartWithCmdArgs;
	// Current disk letter
	wchar_t m_wchCurrentDisk;
	// Count of FAT32/16 fixed disks.
	int m_iFAT32DiskCount;
	// Count of all disks.
	int m_iAllDiskCount;
	// Length of disks' name: ...C:\\D:\\...F:\\...
	int m_iDriverNameLength;
	// All disks' name
	wchar_t m_wchLogicalDrive[INT_DISKCOUNT * 4 + 1];
	// Dummy file main name.
	CString m_strFillFileName;
	// Dummy file extended name.
	CString m_strFillFileExtName;
	// Filling file name.
	CString m_strCurrentFillFileName;
	// Default free space.
	CString m_strDefaultFreeSpace;

	// Count of all fixed disks.
	int m_iFixedDriveCount;
	// List of fixed disk name
	CList<CString, CString&> m_WchDiskLetterList;
	// Counet of fixed disks.
	CList<int, int> m_nDiskIndexList;

	// CListBox objects.
	typedef CTypedPtrList<CObList, CListBox *> ListBoxList;
	ListBoxList m_ListBoxList;

	// CButton objects.
	typedef CTypedPtrList<CObList, CButton *> ButtonList;
	ButtonList m_ButtonList;

	// Threads for FAT32.
	typedef CTypedPtrList<CObList, CWinThread *> WinThreadList;
	WinThreadList m_WinThreadList;

	// Dummy file length.
	__int64 m_iFileLength;
	// Max file length on FAT32.
	__int64 m_iFAT32FileMaxSize;

	// Author's EMail address.
	CString m_strEMailAddress;

	// Command line window handle.
	HANDLE m_hOutPut;
	
	// Self-adapting font size for screen resolution.
	CFont m_font;
	LOGFONT m_lf;

public:
	// Setup main dialog UI.
	void SetAllDiskCheckStatus(void);
	void SetFillButtonStatus(BOOL bStatus);

	// Self-adapting dialog size for screen resolution.
	void ChangeDialogSize(void);
	void SetDialogSize(double scale);

	// Initialize ListBox
	void InitListCtrl(void);
	void SetListInfo(wchar_t * wchDriveLetter, int index, int iDiskIndex);
	void CreateDiskListBox(CRect rectDiskList, int iListBoxID, wchar_t * wchDriveLetter);
	void SetListString(CListBox * pListDisk, wchar_t * wchDriveLetter);
	void SetListStringInfo(CListBox * pListDisk, wchar_t * wchDriveLetter);
	void CountDiskListBoxRect(CRect &rectDiskList, int index);

	// Initialize CheckBox
	void InitCheckCtrl(void);
	void SetCheckInfo(wchar_t * wchDriveLetter, int index, int iDiskIndex);
	void CreateDiskCheckBox(CRect rectDiskCheck, int iCheckBoxID, wchar_t * wchDriveLetter);
	void CountDiskCheckRect(CRect &rectDiskList, int index);

	// Initialize EditBox
	void InitializeDefaultFreeSpace(void);

	// Fill disk space.
	void FillDiskSpace(void);
	void FillAllDiskSpace(__int64 iResidual);
	void FillOneDiskSpace(wchar_t wchDriveLetter[4], __int64 iResidual);
	void FillDiskSpaceFAT32(wchar_t * wchDriveLetter, __int64 iResidual);
	void CreateFillFile(wchar_t * wchDriveLetter, __int64 iFileLength);
	void CreateFillFileFAT32(wchar_t * wchDriveLetter, __int64 iFileLength);
	void RefreshDiskInfo(void);
	void DeleteAllFillFiles(void);
	void DeleteFillFiles(wchar_t * wchDriveLetter);

	// Name of filled dummy files.
	CString GetFillFileName(void);
	void SetFillFileName(CString);
	CString GetFillFileExtName(void);
	void SetFillFileExtName(CString);

	// File length.
	__int64 GetFileLength(void);
	void SetFileLength(__int64 iFileLength);
	__int64 GetFAT32FileMaxSize(void);
	void SetFAT32FileMaxSize(__int64 iFAT32FileMaxSize);

	// Disk information.
	wchar_t GetCurrentDisk(void);
	void SetCurrentDisk(wchar_t wchCurrentDisk);
	int GetFAT32DiskCount(void);
	void SetFAT32DiskCount(int iFAT32DiskCount);
	int GetAllDiskCount(void);
	void SetAllDiskCount(int iAllDiskCount);

	// Output information.
	HANDLE GetOutPutCmdHandle(void);
	void SetOutPutCmdHandle(HANDLE hOutPut);
	CString MakeFillDiskFinishMsg(wchar_t wchDriveLetter);
	CString MakeFillingFileMsg(CString strCurrentFillFileName);
	CString MakeFillFileFinishMsg(CString strCurrentFillFileName);
	void ShowMsg(CString strMsg);
	void AfterAllDiskFillFinished();
	void AfterOneDiskFillFinished(wchar_t * wchDriveLetter);
	void SetStartWithCmdArgs(bool bStartWithCmdArgs);

	// Output command line information.
	void ShowHelpWindow();
	void ShowErrorWindow();
	void ShowFiveSecondsDelay();

	void SendEMailToAuthor();

public:
	afx_msg void OnBnClickedCheckAlldisk();
	afx_msg void OnBnClickedButtonRefreshdisk();
	afx_msg void OnBnClickedButtonDeletefillfile();
	afx_msg void OnBnClickedButtonFilldiskApply();
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	afx_msg void OnDestroy();
	afx_msg void OnShowWindow(BOOL bShow, UINT nStatus);
	afx_msg void OnBnClickedOk();
	afx_msg void OnBnClickedButtonSendEMail();
};
